#ifndef T_BOX_INPUT_H
#define T_BOX_INPUT_H

#include "core/core.h"
extern "C"
{
#ifndef UINT64_C
#define UINT64_C(c)     c ## ULL
#endif
#include "libavformat/avformat.h"
//#include "libavutil/avstring.h"
//#include "libavutil/pixdesc.h"
//#include "libavdevice/avdevice.h"
//#include "libswscale/swscale.h"
//#include "libavcodec/avcodec.h"
//#include "libavcodec/audioconvert.h"
//#include "libavcodec/colorspace.h"
//#include "libavcodec/opt.h"
//#include "libavcodec/avfft.h"
//#include "libavformat/metadata.h"
}

class T_Box_Input : public QObject
{
    Q_OBJECT
protected:
    ByteIOContext m_bioc;
    quint8* m_io_buffer;
    QString m_media_name;
public:
    explicit T_Box_Input();
    virtual ~T_Box_Input();
    virtual bool isValid() = 0;
    virtual void close() = 0; //FIXME: finish
    ByteIOContext *getByteIOContext();
    AVFormatContext	*getAVFormatContext();
    void debugMode(bool b);
    bool debugMode();
    QString mediaName();
    void mediaName(const QString a_name);
protected:
    virtual int bufferSize() = 0;
    virtual qint64 size() = 0;
    virtual qint64 pos() = 0;
    virtual bool seek(qint64 offset) = 0;
    virtual QByteArray wait_read(qint64 a_max_size) = 0;
protected:
    AVInputFormat *getAVInputFormat();
    int64_t av_seek(int64_t offset, int whence);
    int av_read_packet(uint8_t *buf, int buf_size);
    static int callback_read_packet(void *opaque, uint8_t *buf, int buf_size);
    static int64_t callback_seek(void *opaque, int64_t offset, int whence);
    QString p_seek_whence_name(int whence);
private:
    class T_Box_InputPrivate *d_ptr;
    Q_DECLARE_PRIVATE(T_Box_Input)
};

#endif // T_BOX_INPUT_H
